package demo.util;

import org.apache.hadoop.hive.service.ThriftHive;
import org.apache.hive.service.cli.CLIServiceClient;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TSocket;

import java.util.List;

/**
 * Created by Administrator on 2017/12/7 0007.
 */
public class HiveThriftClient {
    public static void main(String[] args) throws Exception{
        //创建socket连接
        final TSocket tSocket = new TSocket("192.168.72.141", 10000);

        //创建一个协议
        final TProtocol tProtocol = new TBinaryProtocol(tSocket);

        //创建Hive Client
        //final HiveClient client = new HiveClient(tProtocol)
        ThriftHive.Client client = new ThriftHive.Client(tProtocol);
        tSocket.open();

        client.execute("desc t4");
        List items = client.fetchAll();
        for (Object item : items) {
            System.out.println(item);
        }
        tSocket.close();
    }
}
